<?php
namespace app\admin\controller;

use app\admin\module\CateModule;
use app\BaseController;
use app\Request;
use app\common\validate\Cate as CateValidate;
use think\Exception;

class Cate extends BaseController{

    public function all(){
        $data = CateModule::all();
        return $this->success('ok',$data);
    }

    public function index(Request $request){
        $data = CateModule::page($request->param("pageSize",10));
        return $this->success('ok',$data);
    }

    public function create(Request $request){
        $post = $request->post();

        $validate = new CateValidate();
        if(!$validate->check($post)){
            throw new Exception($validate->getError());
        }

        CateModule::create($post);
        return $this->success("ok");
    }

    public function update(Request $request){
        $post = $request->post();

        $validate = new CateValidate();
        if(!$validate->check($post)){
            throw new Exception($validate->getError());
        }

        CateModule::update($post);
        return $this->success("ok");
    }

    public function remove(Request $request){
        $id = $request->param('id');
        CateModule::del($id);
        return $this->success('ok');
    }
}